package com.hua.designpattern.behavioral.memento;

import java.util.ArrayList;
import java.util.List;

public class MemontoManager {
	private BaseObject baseObject;
	private List<BaseObject> objectList = new ArrayList<BaseObject>();

	public MemontoManager(BaseObject baseObject) {
		super();
		this.baseObject = baseObject;
	}

	public void saveToMemonto(BaseObject baseObject) {
		System.out.println("save point: " + baseObject);
		objectList.add(new BaseObject(baseObject));
	}

	public BaseObject getFromMemonto(int step) {
		int index = objectList.size() - step;
		if (index >= objectList.size() || index < 0) {
			throw new ArrayIndexOutOfBoundsException(index);
		}
		return baseObject.SetBaseObject(objectList.get(index));
	}
}
